home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Lose Your Marbles! 1.0 / source / ls code ƒ / ls find.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.5 KB  |  209 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        ls find.c
  4.  
  5. Purpose:    This module handles the "find problem" option.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program in a file named "GNU General Public License".
  19. If not, write to the Free Software Foundation, 675 Mass Ave,
  20. Cambridge, MA 02139, USA.
  21.  
  22. \**********************************************************************/
  23.  
  24. #include "ls find.h"
  25. #include "ls meat.h"
  26. #include "dialogs.h"
  27. #include "menus.h"
  28. #include "program globals.h"
  29.  
  30. static    Boolean            gIsShowingFind;
  31. static    short            gProblemRow1, gProblemRow2, gProblemColumn1, gProblemColumn2;
  32.  
  33. void InitFind(void)
  34. {
  35.     gIsShowingFind=FALSE;
  36. }
  37.  
  38. void FindDispatch(ExtendedWindowDataHandle theData)
  39. {
  40.     if (FindProblem(&gProblemRow1, &gProblemColumn1, &gProblemRow2, &gProblemColumn2))
  41.     {
  42.         gIsShowingFind=TRUE;
  43.         AdjustMenus();
  44.         DrawMenuBar();
  45.         UpdateTheWindow(theData);
  46.     }
  47.     else
  48.     {
  49.         PositionDialog('ALRT', smallAlert);
  50.         ParamText("\pThere are no problems on the current playing board.","\p","\p","\p");
  51.         NoteAlert(smallAlert, 0L);
  52.     }
  53. }
  54.  
  55. Boolean ShowingFindQQ(void)
  56. {
  57.     return gIsShowingFind;
  58. }
  59.  
  60. void DontShowFind(WindowDataHandle theData)
  61. {
  62.     gIsShowingFind=FALSE;
  63.     AdjustMenus();
  64.     DrawMenuBar();
  65.     UpdateTheWindow((ExtendedWindowDataHandle)theData);
  66. }
  67.  
  68. void GetProblemPositions(short *row1, short *column1, short *row2, short *column2)
  69. {
  70.     *row1=gProblemRow1;
  71.     *column1=gProblemColumn1;
  72.     *row2=gProblemRow2;
  73.     *column2=gProblemColumn2;
  74. }
  75.  
  76. Boolean FindProblem(short *problemRow, short *problemColumn, short *problemRow2,
  77.     short *problemColumn2)
  78. {
  79.     short            theRow, theColumn;
  80.     short            rowIter, columnIter;
  81.     short            startRow, startColumn;
  82.     
  83.     /* check for identical pieces in the same row */
  84.     for (theRow=0; theRow<gNumRows; theRow++)
  85.     {
  86.         for (theColumn=0; theColumn<gNumColumns-1; theColumn++)
  87.         {
  88.             if (Board[theRow][theColumn]>0)
  89.             {
  90.                 for (columnIter=theColumn+1; columnIter<gNumColumns; columnIter++)
  91.                 {
  92.                     if (Board[theRow][theColumn]==Board[theRow][columnIter])
  93.                     {
  94.                         *problemRow=*problemRow2=theRow;
  95.                         *problemColumn=theColumn;
  96.                         *problemColumn2=columnIter;
  97.                         return TRUE;
  98.                     }
  99.                 }
  100.             }
  101.         }
  102.     }
  103.     
  104.     /* check for identical pieces in the same column */
  105.     for (theColumn=0; theColumn<gNumColumns; theColumn++)
  106.     {
  107.         for (theRow=0; theRow<gNumRows-1; theRow++)
  108.         {
  109.             if (Board[theRow][theColumn]>0)
  110.             {
  111.                 for (rowIter=theRow+1; rowIter<gNumRows; rowIter++)
  112.                 {
  113.                     if (Board[theRow][theColumn]==Board[rowIter][theColumn])
  114.                     {
  115.                         *problemRow=theRow;
  116.                         *problemRow2=rowIter;
  117.                         *problemColumn=*problemColumn2=theColumn;
  118.                         return TRUE;
  119.                     }
  120.                 }
  121.             }
  122.         }
  123.     }
  124.     
  125.     theRow=gNumRows-2;
  126.     theColumn=0;
  127.     
  128.     while (theColumn<gNumColumns-1)
  129.     {
  130.         startRow=theRow;
  131.         startColumn=theColumn;
  132.         
  133.         while ((startRow<gNumRows-1) && (startColumn<gNumColumns-1))
  134.         {
  135.             if (Board[startRow][startColumn]>0)
  136.             {
  137.                 rowIter=startRow+1;
  138.                 columnIter=startColumn+1;
  139.                 
  140.                 while ((rowIter<gNumRows) && (columnIter<gNumColumns))
  141.                 {
  142.                     if (Board[startRow][startColumn]==Board[rowIter][columnIter])
  143.                     {
  144.                         *problemRow=startRow;
  145.                         *problemColumn=startColumn;
  146.                         *problemRow2=rowIter;
  147.                         *problemColumn2=columnIter;
  148.                         return TRUE;
  149.                     }
  150.                     
  151.                     rowIter++;
  152.                     columnIter++;
  153.                 }
  154.             }
  155.             
  156.             startRow++;
  157.             startColumn++;
  158.         }
  159.         
  160.         if (theRow==0)
  161.             theColumn++;
  162.         else
  163.             theRow--;
  164.     }
  165.     
  166.     theRow=1;
  167.     theColumn=0;
  168.     
  169.     while (theColumn<gNumColumns-1)
  170.     {
  171.         startRow=theRow;
  172.         startColumn=theColumn;
  173.         
  174.         while ((startRow>=0) && (startColumn<gNumColumns))
  175.         {
  176.             if (Board[startRow][startColumn]>0)
  177.             {
  178.                 rowIter=startRow-1;
  179.                 columnIter=startColumn+1;
  180.                 
  181.                 while ((rowIter>=0) && (columnIter<gNumColumns))
  182.                 {
  183.                     if (Board[startRow][startColumn]==Board[rowIter][columnIter])
  184.                     {
  185.                         *problemRow=startRow;
  186.                         *problemColumn=startColumn;
  187.                         *problemRow2=rowIter;
  188.                         *problemColumn2=columnIter;
  189.                         return TRUE;
  190.                     }
  191.                     
  192.                     rowIter--;
  193.                     columnIter++;
  194.                 }
  195.             }
  196.             
  197.             startRow--;
  198.             startColumn++;
  199.         }
  200.         
  201.         if (theRow==gNumRows-1)
  202.             theColumn++;
  203.         else
  204.             theRow++;
  205.     }
  206.     
  207.     return FALSE;        /* no problems found */
  208. }
  209.